require('../css/login.less')

console.log('我是login.js');
let tel = document.querySelector('#tel')
let pwd = document.querySelector('#pwd')
let loginBtn = document.querySelector('.save-btn')
let msg = document.querySelector('.msg')




document.querySelector('.jump-text').addEventListener('click', function (e) {
    location.href = './register.html'
})




loginBtn.addEventListener("click", function (e) {
    if (tel.value && pwd.value) {
        let reg = /^1[3|4|5|6|7|8|9][0-9]{9}$/
        if (!reg.test(tel.value)) {
            msg.textContent = '手机号输入有误'
            return
        }
        let data = {
            account: tel.value,
            password: pwd.value
        }
        $http.post('/users/login', data, function (res) {
            if (res.status == 0) {
                localStorage.setItem('user', JSON.stringify(res.data.user))
                utils.createToast(0,'登录成功')
                setTimeout(function () {
                    location.href = './home.html'
                }, 2000)
            } else {
                utils.createToast(1,res1.msg)
            }
        })
    }
})